package com.itheima.dubbo.web;

import com.itheima.dubbo.HelloFaceService;
import com.itheima.dubbo.WhatFaceService;
import com.itheima.pojo.User;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by jojo
 * @Date 2022/3/25
 * @Description
 */
@RestController
public class HelloController {

//    @DubboReference(timeout = 2000)
//    @DubboReference(timeout = 3000,retries = 1)      //轮询
//    @DubboReference(version = "2.0.0",check = false)//启动时检查设置
//    @DubboReference(version = "2.0.0", loadbalance = "roundrobin",check = false)  //负载均衡默认是 random
    @DubboReference(check = false)//关闭启动检查
    private HelloFaceService helloFaceService;
    @DubboReference
    private WhatFaceService whatFaceService;

    @GetMapping("hello")
    public String demo(String name){
//        String name="jojo";
//        String hello = helloFaceService.hello(name);
//        // 本端是否为消费端，这里会返回true
//        boolean consumerSide = RpcContext.getContext().isProviderSide();
//        System.out.println("consumerSide = " + consumerSide);
//        // 获取最后一次调用的提供方IP地址
//        String remoteHost = RpcContext.getContext().getRemoteHost();
//        System.out.println("remoteHost = " + remoteHost);
//        // 获取当前服务配置信息，所有配置信息都将转换为URL的参数
//        String application = RpcContext.getContext().getUrl().getParameter("application");
//        System.out.println("application = " + application);
//        String what = whatFaceService.what();
        RpcContext.getContext().setAttachment("jojo","killerqueen");
        return helloFaceService.hello(name) ;
    }


    @GetMapping("user")
    public User demo02(){
       return helloFaceService.byUser();
    }
}
